package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.Events;
import com.egao.orderB.service.EventsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 事件记录
 * @author : Doman
 * @date : 2021-05-11 16:40:00
 * @version ：1.0
 */

@Api(tags = "事件记录")
@RestController
@RequestMapping("/api/orderB/events")
public class EventsController extends BaseController {

	@Autowired
	private EventsService eventsService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:events:list')")
    //@OperLog(value = "事件记录", desc = "分页查询")
    @ApiOperation(value ="分页查询事件记录",notes = "" +
        "date1:充值开始时间\n" +
        "date2:充值结束时间\n" +
       "返回\n\n\n" +
       "id:id\n" +
       "customerId:客户id\n" +
       "customer:客户名称\n" +
       "eventDate:事件时间\n" +
       "billId:bill id\n" +
       "driverId:司机id\n" +
       "driver:司机姓名\n" +
       "carNo:车牌\n" +
       "carTeamId:车队id\n" +
       "carTeam:车队名称\n" +
       "content:内容\n" +
       "remark:备注\n" +
       "type:类型(报价,订单,客户,车队,司机)\n" +
       "createTime:创建时间\n" +
       "createUser:创建人\n" +
       "updateTime:更新时间\n" +
       "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult list(PageResult2<T> page, Events events) throws Exception{
        return eventsService.list(page, events, getLoginUser());
    }

    /**
     * 查询全部事件记录
     */
    @PreAuthorize("hasAuthority('orderB:events:list')")
    //@OperLog(value = "事件记录", desc = "查询全部")
    @ApiOperation(value ="查询全部事件记录",notes = "" +
            "customerId 客户id\n" +
            "customer 客户名称\n" +
            "type 类型\n" +
            "date1 eventDate开始时间\n" +
            "date2 eventDate结束时间\n" +
            "返回\n\n" +
            "customer 客户名称\n" +
            "messageNums 消息数量\n" +
            "",httpMethod = "POST")
    @PostMapping("/listAll")
    public JsonResult listAll(Events events){
        return eventsService.list(events, getLoginUser());
    }

    /**
     * 查询事件记录所有的客户
     */
    @PreAuthorize("hasAuthority('orderB:events:list')")
    //@OperLog(value = "事件记录", desc = "查询全部")
    @ApiOperation(value ="查询事件记录所有的客户",notes = "" +
            "返回\n\n" +
            "customer 客户名称\n" +
            "messageNums 消息数量\n" +
            "",httpMethod = "POST")
    @PostMapping("/allCustomer")
    public JsonResult allCustomer(Events events){
        return eventsService.allCustomer(events, getLoginUser());
    }

    /**
     * 根据id查询事件记录
     */
    @PreAuthorize("hasAuthority('orderB:events:list')")
    //@OperLog(value = "事件记录", desc = "根据id查询")
    @ApiOperation("根据id查询事件记录")
    @PostMapping("/get")
    public JsonResult get(Events events) {
        return eventsService.getById(events);
		// 使用关联查询
        //PageParam<events> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<events> records = eventsService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加事件记录
     */
    @PreAuthorize("hasAuthority('orderB:events:save')")
    @OperLog(value = "事件记录", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加事件记录",notes = "" +
           "customerId:客户id\n" +
           "customer:客户名称\n" +
            "eventDate:事件时间\n" +
            "type:类型(报价,订单,客户,车队,司机)\n" +
//           "billId:bill id\n" +
//           "driverId:司机id\n" +
//           "driver:司机姓名\n" +
//           "carNo:车牌\n" +
//           "carTeamId:车队id\n" +
//           "carTeam:车队名称\n" +
           "content:内容\n" +
           "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, Events events) {
        return eventsService.save(events, getLoginUser());
    }

    /**
     * 修改事件记录
     */
    @PreAuthorize("hasAuthority('orderB:events:update')")
    @OperLog(value = "事件记录", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改事件记录",notes = "" +
           "id:id\n" +
           "customerId:客户id\n" +
           "customer:客户名称\n" +
            "eventDate:事件时间\n" +
            "type:类型(报价,订单,客户,车队,司机)\n" +
//           "billId:bill id\n" +
//           "driverId:司机id\n" +
//           "driver:司机姓名\n" +
//           "carNo:车牌\n" +
//           "carTeamId:车队id\n" +
//           "carTeam:车队名称\n" +
           "content:内容\n" +
           "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, Events events) {
        return eventsService.update(events, getLoginUser());
    }

    /**
     * 删除事件记录
     */
    @PreAuthorize("hasAuthority('orderB:events:remove')")
    @OperLog(value = "事件记录", desc = "删除", result = true)
    @ApiOperation("删除事件记录")
    @PostMapping("/remove")
    public JsonResult remove(Events events ) {
        return eventsService.remove(events, getLoginUser());
    }

    /**
     * 批量添加事件记录
     */
    /**@RequiresPermissions("orderB:events:save")
    @OperLog(value = "事件记录", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Events> list) {
        if (eventsService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改事件记录
     */
    /**@RequiresPermissions("orderB:events:update")
    @OperLog(value = "事件记录", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Events> batchParam) {
        if (batchParam.update(eventsService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除事件记录
     */
    /**@RequiresPermissions("orderB:events:remove")
    @OperLog(value = "事件记录", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (eventsService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
